<!--
 * @Author: xinqiao lxq1990.0716@qq.com
 * @Date: 2023-12-04 11:46:12
 * @LastEditors: xinqiao lxq1990.0716@qq.com
 * @LastEditTime: 2023-12-07 17:40:01
 * @FilePath: \components\src\components\demo-box.vue
 * @Description: demo展示
-->
<template>
  <section class="demo-box">
    <section class="demo-box-meta">
      <div class="demo-box-title">
        <slot name="title" />
      </div>
      <div class="demo-box-description demo-box-inner">
        <div class="code-expand-icon">
          <a-tooltip :title="codeVisible ? '隐藏代码' : '显示代码'">
            <img
              v-if="!codeVisible"
              src="@/assets/image/expand.svg"
              :class="codeVisible ? 'hide' : 'show'"
              @click="switchCode"
            />
            <img
              v-else
              src="@/assets/image/unexpand.svg"
              :class="codeVisible ? 'show' : 'hide'"
              @click="switchCode"
            />
          </a-tooltip>
        </div>
        <div v-if="$slots.description" class="slot-description">
          <slot name="description" />
        </div>
      </div>
    </section>
    <section v-show="codeVisible" class="demo-box-code"><slot name="code" /></section>

    <section class="demo-box-view demo-box-inner">
      <slot name="view" />
    </section>
  </section>
</template>

<script lang="ts">
  import { defineComponent, ref } from 'vue';

  export default defineComponent({
    name: 'DemoBox',
    setup() {
      const codeVisible = ref(false);
      const switchCode = () => {
        codeVisible.value = !codeVisible.value;
      };
      return {
        codeVisible,
        switchCode,
      };
    },
  });
</script>
<style lang="less">
  .demo-box {
    position: relative;
    width: 100%;
    margin: 16px 0 0;
    border: 1px solid #f0f0f0;
    border-radius: 2px;
    transition: all 0.2s;
    .demo-box-inner {
      position: relative;
      padding: 16px;
    }
    .hide {
      display: none;
    }
    .show {
      display: block;
    }
    .code-expand-icon {
      position: absolute;
      width: 26px;
      height: 16px;
      bottom: -9px;
      left: 50%;
      cursor: pointer;
      img {
        // transform: translateY(-8px);
        width: 16px;
        height: 16px;
        margin-left: 5px;
      }
    }
    .slot-description {
      margin: 0 24px;
      min-height: 44px;
      line-height: 44px;
    }
    .demo-box-title {
      position: absolute;
      top: -14px;
      margin-left: 16px;
      padding: 1px 8px;
      font-weight: bold;
    }
    .demo-box-description {
      p {
        margin-bottom: 0;
      }
      width: 100%;
      font-size: 14px;
      line-height: 2;
      border-bottom: 1px dashed #f0f0f0;
    }
    .demo-box-view {
      position: fixed;
      z-index: 9;
      top: 0;
      bottom: 0;
      right: 88px;
      width: 427px;
      height: 860px;
      margin: auto;
      padding: 0 !important;
    }
    .demo-box-code {
      padding: 0 24px;
      border-bottom: 1px dashed #f0f0f0;
    }
  }
</style>
